package com.college.collegeinfomanage.service.impl;

import com.college.collegeinfomanage.entity.Faculty;
import com.college.collegeinfomanage.mapper.AcademicProgramsMapper;
import com.college.collegeinfomanage.mapper.FacultyMapper;
import com.college.collegeinfomanage.mapper.ResearchStrengthMapper;
import com.college.collegeinfomanage.mapper.UniversityMapper;
import com.college.collegeinfomanage.service.DashboardService;
import com.college.collegeinfomanage.vo.DashboardVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DashboardServiceImpl implements DashboardService {

    @Resource
    private UniversityMapper universityMapper;

    @Resource
    private AcademicProgramsMapper academicProgramsMapper;

    @Resource
    private FacultyMapper facultyMapper;

    @Resource
    ResearchStrengthMapper researchStrengthMapper;


    @Override
    public DashboardVO summary() {
        DashboardVO dashboardVO = new DashboardVO();
        //高校数量汇总
        dashboardVO.setUniversityCount(Math.toIntExact(universityMapper.selectCount(null)));
        //教师数量汇总
        List<Faculty> faculties = facultyMapper.selectList(null);
        int teacherCount = 0;
        for (Faculty faculty : faculties) {
            teacherCount += faculty.getFacultyCount();
        }
        dashboardVO.setTeacherCount(teacherCount);
        //专业数量汇总
        dashboardVO.setMajorCount(Math.toIntExact(academicProgramsMapper.selectCount(null)));
        //科研数量汇总
        dashboardVO.setResearchCount(Math.toIntExact(researchStrengthMapper.selectCount(null)));
        return dashboardVO;

    }
}
